﻿<html>
<form method="POST" action="staffCheck.php">
	請輸入送貨單號：<input type="text" name="_id"></br>
	<input type="submit" value="確定">
</form>
<hr>
<?php
$_id = $_POST['_id'];
$_Weight = $_POST['_Weight'];
$_Length  = $_POST['_Length'];
$_width  = $_POST['_width'];
$_height  = $_POST['_height'];

$link=mysql_connect("localhost", "root" ,"1123");
mysql_select_db("dd") or die("No database");
$success = False;
if($_Weight > 0)
{
	$query = "  Update shipment 
				Set weight = " . $_Weight .
				" where tracking_number = '" . $_id . "';";
	mysql_query($query) or die("Error Message:".mysql_error());
	$success = True;
}
if($_Length > 0)
{
	$query = " Update shipment 
				Set length = " . $_Length .
				" where tracking_number = '" . $_id . "';";	
	mysql_query($query) or die("Error Message:".mysql_error());
	$success = True;
}
if($_width > 0)
{
	$query = " Update shipment 
				Set width = " . $_width .
				" where tracking_number = '" . $_id . "';";	
	mysql_query($query) or die("Error Message:".mysql_error());
	$success = True;
}
if($_height > 0)
{
	$query = " Update shipment
				Set height = " . $_height .
				" where tracking_number = '" . $_id . "';";	
	mysql_query($query) or die("Error Message:".mysql_error());
	$success = True;
}

if($_id != 0)
{
	$query = "	select weight, length, width, height, name, start_warehouse
				from shipment natural left outer join at
				where tracking_number = '" . $_id . "';";
	$result = mysql_query($query) or die("Error Message:".mysql_error());
	$main = '';
	if(list($a, $b, $c, $d, $e, $start_w) = mysql_fetch_row($result))
	{
		//插入at表格
		$query = "Insert into at values('" . $_id . "', '" . $start_w . "');";
		$result = mysql_query($query);
		//手動輸入長寬高
		$found = TRUE;
		$main .='<form method="POST" action="staffCheck.php"><input type="hidden" name="_id" value = ' . $_id . ">";
		$main .='<table width=250 border="solid">';
		$main .=
		'
		<tr>
			<td align="center">重量</td><td><input type="text" name="_Weight" value =' . $a . '>公斤</td>
		</tr>
		<tr>
			<td align="center">長</td><td><input type="text" name="_Length" value =' . $b . '>公分</td>
		</tr>
		<tr>
			<td align="center">寬</td><td><input type="text" name="_width" value =' . $c . '>公分</td>
		</tr>
		<tr>
			<td align="center">高</td><td><input type="text" name="_height" value =' . $d . '>公分</td>
		</tr>
		</table>';
	}
	else
	{
		$found = FALSE;
	}
	if($found)
	{
		$main .='<input type="submit" value="確定"></form>';	
	}
	else
	{
		$main .= "此單號不存在，請重新輸入。";
	}
	echo $main;
	if($success)
	{
		echo "修改成功！";
	}
	mysql_close ($link);
}
?>
</html>